package homework;

import java.io.*;

/**
 * @classname:demo01
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/15 16:30
 * @version: 0.1
 * @since:1.8
 */
public class demo01 {
    public static void main(String[] args) {
        String path = "D:\\mulu\\a.txt";
        copyOf(path);

    }

    private static void copyOf( String sourcePath) {
        File file = new File("D:\\mulu\\Copyof");
        if(!file.exists()){
            file.mkdirs();
        }
        String substring = sourcePath.substring(sourcePath.lastIndexOf(File.separator )+ 1);

        try (
                InputStream in = new FileInputStream(sourcePath);
                OutputStream out = new FileOutputStream(new File(file,substring));
        ) {
            byte[] buf = new byte[1024];
            int len = 0;
            while ((len = in.read(buf)) != -1) {
                out.write(buf, 0, len);
            }
            System.out.println("success");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
